package cn.blog.controller.back;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.blog.controller.BaseServlet;
import cn.blog.entity.origin.Employee;
import cn.blog.entity.origin.ManagePeople;
import cn.blog.service.back.ManagePeopleService;

@WebServlet("/back/managepeople")
public class Managepeople extends BaseServlet {
	ManagePeopleService mps = new ManagePeopleService();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		mps = new ManagePeopleService();
		List<ManagePeople> mplst = mps.getManaName();
		req.setAttribute("mplst", mplst);
		forward("back/managepeople");

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		// 获取请求参数
		String action = req.getParameter("action");
		if (action.equals("add")) {
			// 获取请求参数
			String accont = req.getParameter("accont");
			String name = req.getParameter("name");
			String password = req.getParameter("password");
			String phone = req.getParameter("phone");
			ManagePeople mp = new ManagePeople();
			mp.setManaName("accont");
			mp.setManaName("name");
			mp.setManaName("password");
			mp.setManaName("phone");
			mps.addManaName(accont, name, password, phone);
			list(req, resp);
			redirect("/back/managepeople");// 重定向到列表
		} 

	}

	protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		mps = new ManagePeopleService();
		ManagePeople mp = (ManagePeople) req.getSession().getAttribute("mp");
		List<ManagePeople> mplst = mps.getManaName();
		req.setAttribute("mplst", mplst);
	}
}
